package com.study.mr.partitioner;


import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.CombineTextInputFormat;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/**
 * MR的驱动类：主要用于提交任务
 */
public class WordCountDriver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        //声明配置对象
        Configuration conf = new Configuration();
        //声明Job对象
        Job job = Job.getInstance(conf);
        //指定当前Job驱动类
        job.setJarByClass(WordCountDriver.class);
        //指定当前Job的Mapper和Reducer
        job.setMapperClass(WordCountMapper.class);
        job.setReducerClass(WordCountReducer.class);
        //指定Map端输出的数据类型
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);
        //指定最终输出结果的数据类型
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);

        //指定ReduceTask的数量
        job.setNumReduceTasks(2);

        //指定输入数据和输出数据的目录
        FileInputFormat.setInputPaths(job,new Path("D:\\hadoopbook\\demodate\\wcinput"));
        FileOutputFormat.setOutputPath(job,new Path("D:\\hadoopbook\\demodate\\wcoutput2"));
//        FileInputFormat.setInputPaths(job,new Path(args[0]));
//        FileOutputFormat.setOutputPath(job,new Path(args[1]));
        //提交Job
        job.waitForCompletion(true);
    }
}
